<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let num = Math.floor(Math.random() * 100) + 1
    let shu = +prompt('请输入1-100之间的一个数')
    let jihui = 1;
    let i = 3
    while (jihui <= 3) {
      if (shu > num) {
        let j = 3 - jihui
        shu = +prompt(`太大了，你还剩${j}次机会`);
        jihui++;
      }
      if (shu < num) {
        let j = 3 - jihui
        shu = +prompt(`太小了，你还剩${j}次机会`);
        jihui++;
      }
      if (shu === num) {
        alert('恭喜你！猜对了')
        break;
      }
      if (jihui === 3) {
        alert(`很遗憾，你已经猜了${jihui}次了，没机会了，正确答案是${num}`)
        break;
      }
    }

  </script>
</body>

</html>